<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片区域 -->
    <el-card>
      <el-row>
        <el-col>
          <el-input placeholder="请输入内容" class="input-with-select">
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>

      <!-- 订单列表表格区域 -->
      <el-table :data="ordersData" border style="width: 100%">
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column prop="order_number" label="订单编号" width="180"></el-table-column>
        <el-table-column prop="order_price" label="订单价格" width="180"></el-table-column>
        <el-table-column label="是否付款">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.order_pay ==='0'" type="danger">未付款</el-tag>
            <el-tag type="success" v-else>已付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货"></el-table-column>
        <el-table-column prop="create_time" label="下单时间">
          <template slot-scope="socpe">{{socpe.row.create_time|formatDate}}</template>
        </el-table-column>
        <el-table-column label="操作">
          <template >
            <el-button size="mini" type="primary" icon="el-icon-edit" @click = "editAddrShowDialog"></el-button>
            <el-button size="mini" type="success" icon="el-icon-location-outline" @click = "logisticsShowDialog"></el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[5, 10, 15,20]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </el-card>

    <!-- 修改地址对话框 -->
    <el-dialog title="修改地址" :visible.sync="editAddrdialogVisible" width="50%" @close = "editAddrClosed">
      <el-form
        :model="addrRuleForm"
        :rules="addrRules"
        ref="addrFormRef"
        label-width="100px"
        class="demo-ruleForm" 
         >
        <el-form-item label="省市县/区" prop="addr">
           <el-cascader
    v-model=" addrRuleForm.addr"
    :options="cityData"
    :props="{ expandTrigger: 'hover' }"
      ></el-cascader>
        </el-form-item>
          <el-form-item label="活动名称" prop="addrDetail">
          <el-input v-model="addrRuleForm.addrDetail"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editAddrdialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="editAddrdialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>

    <!-- 查看物流信息对话框 -->
    <el-dialog
  title="查看物流信息"
  :visible.sync="logisticsDialogVisible"
  width="50%">
  <el-timeline>
    <el-timeline-item
      v-for="( logistics, index) in   LogisticsInformation"
      :key="index"
      :timestamp="logistics.time">
      {{logistics.context}}
    </el-timeline-item>
  </el-timeline>
  <span slot="footer" class="dialog-footer">
    <el-button @click="logisticsDialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="logisticsDialogVisible = false">确 定</el-button>
  </span>
</el-dialog>
  </div>
</template>

<script>
//导入省市县城市数据
 import cityData from './city_data.js'
export default {
  name: "Order",
  data() {
    return {
      //获取请求的订单数据参数
      queryInfo: {
        query: "",
        pagenum: 1,
        pagesize: 10
      },
      //订单数据
      ordersData: [],
      //订单数据的条数
      total: 0,
      // 修改地址对话框显示与隐藏属性
      editAddrdialogVisible: false,
      //修改地址表单数据
      addrRuleForm:{
        addr:[],
        addrDetail:''
      },
      //修改地址表单验证规则
      addrRules:{
        addr:[
           { required: true, message: '请输入地址', trigger: 'blur' }
        ],
        addrDetail:[
          { required: true, message: '请输入详细地址', trigger: 'blur' }
        ]
      },
      //城市列表数据
       cityData:cityData,
      //查看物流信息对话框隐藏于显示
       logisticsDialogVisible:false,
       //物流信息数据
       LogisticsInformation : []
    };
  },
  created() {
    this.getOrdersList();
  },
  methods: {
    async getOrdersList() {
      const { data: res } = await this.$http.get("orders", {
        params: this.queryInfo
      });
      if (res.meta.status != 200)
        return this.$message.error("获取订单列表失败");
      (this.ordersData = res.data.goods), (this.total = res.data.total);
      console.log(this.orderData, this.total);
    },
    //改变订单列表每页的数据条数方法
    handleSizeChange(newPageSize) {
      this.queryInfo.pagesize = newPageSize;
      this.getOrdersList();
    },
    //改变订单列表每页方法
    handleCurrentChange(newPageNum) {
      this.queryInfo.pagenum = newPageNum;
      this.getOrdersList();
    },
    editAddrShowDialog(){
      this.editAddrdialogVisible = true;
    },
    editAddrClosed(){
      this.$refs.addrFormRef.resetFields()
    },
    async logisticsShowDialog(){
       this.logisticsDialogVisible = true;

    const {data:res} = await this.$http.get('/kuaidi/1106975712662')
        if(res.meta.status !=200) return this.$message.erro("获取物流信息失败")
          this.LogisticsInformation = res.data;
    }
  }
};
</script>


<style lang="less" scoped>
.el-input {
  width: 500px;
}
.el-cascader{
  width: 500px;
}
</style>